<%--
功能：输出专场目录Link
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%@ tag import="org.springframework.context.ApplicationContext" %>
<%@ tag import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ tag import="com.probiz.estore.catalog.service.VirtualCategoryManager" %>
<%@ tag import="com.probiz.estore.common.model.catalog.VirtualCategory" %>

<%@ attribute name="category" type="com.probiz.estore.common.model.catalog.VirtualCategory" required="false" description="内容"%>
<%@ attribute name="categoryId" type="java.lang.Integer" required="false" description="目录id 如果category 无指定,则可用这个"%>
<%@ attribute name="categoryCode" type="java.lang.String" required="false" description="目录id 如果category、categoryId 无指定,则必须用这个"%>


<%
	ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
	VirtualCategoryManager virtualCategoryManager = (VirtualCategoryManager) ctx.getBean("virtualCategoryManager");
	
	VirtualCategory targetCategory = category;
	if(null == targetCategory){
		if(null != categoryId){
			targetCategory = virtualCategoryManager.getById(categoryId);
		}else{
			targetCategory = virtualCategoryManager.getCategoryByCode(categoryCode);
		}
	}	
	if(null != targetCategory){
		if(!targetCategory.getCategoryType().equals(VirtualCategory.TYPE_LINK)){
			request.setAttribute("target","_self");
			String uri = virtualCategoryManager.getUriByCategoryId(targetCategory.getCategoryId());
			request.setAttribute("categoryUri",application.getAttribute("ctxPath")+uri);		
		}else{
			request.setAttribute("categoryUri",targetCategory.getLinkUrl());	
			request.setAttribute("target",(targetCategory.getLinkTarget()==1)?"_blank":"_self");
		}
	}	

%>
href="${categoryUri}" target="${target}"
